<?php

namespace Modules\Market;

use Modules\Order\Entities\BaseOrder as Order;

use Setting;
use Modules\Market\Entities\Tenant;
use Modules\Asset\Entities\Resale;
use Cache;

class Cron
{
	public function handle($schedule)
	{
		$that = $this;
		$schedule->call(function() use ($that) {
			try {
				$that->everyMinute();
			}
			catch (\Throwable $e) {
                \Log::error('cron任务异常');
                \Log::error($e->getMessage());
            }
		})->everyMinute();
	}

	public function everyMinute()
	{

		// $isAutoBuy = intVal(@Setting::get('sys_market')['is_auto_buy'] ?: 0);

		// if ($isAutoBuy) {

		// 	$tenantId = intVal(@Setting::get('sys_market')['auto_buy_tenant_id'] ?: 0);
		// 	$timeout = intVal(@Setting::get('sys_market')['auto_buy_timeout'] ?: 0);

		// 	$tenant = Tenant::getEntity([
	 //            'id' => $tenantId
	 //        ], false);

	 //        // \Log::error($tenant->title);

	 //        if ($tenant) {
	 //        	$time = date('Y-m-d H:i:s', strtotime('-' . $timeout . ' minutes'));

	 //        	// \Log::error($time);

		// 		$list = Resale::where('is_allow_fast_match', 1)->status('pending')->where('created_at', '<', $time)->inRandomOrder()->take(100)->get();

		// 		foreach ($list as $resale) {
		// 			// 3为自动购买
		//             $resale->completeWithTenant($tenant, 3);

		//             \Log::error('自动购买' . $resale->id);
		//         }
		//     }
		// }

	}
}